/*
 * power.c
 *
 *  Created on: 2011-12-14
 *      Author: Jessay
 */

#include "tangoc.h"

#define power_mode 	51

static unsigned char last_mode;

unsigned char get_power_mode()
{
	unsigned char wbuf[1], rbuf[1];
	int ret;

	ioctl(gdev, DEFAULT, 0);
	wbuf[0] = power_mode;
	ret = write(gdev, wbuf, 1);
	ret = read(gdev, rbuf, 1);
	return rbuf[0];
}

void set_power_mode(unsigned char data)
{
	unsigned char wbuf[2];
	int ret;

	ioctl(gdev, DEFAULT, 0);
	wbuf[0] = power_mode;
	wbuf[1] = data & 0xFF;
	ret = write(gdev, wbuf, 2);
}

void active_power()
{
	last_mode = get_power_mode();
	if(last_mode!=0) set_power_mode(0);
	printf("last power mode = %d\n", last_mode);
}

void restore_power_mode()
{
	set_power_mode(last_mode);
}


